added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSSL3FullScreen / MainPage.xaml.cs
blobbf2e12f534ac0cd0caf9bec0631c39089cf70a3e
1 /****************************** Module Header ******************************\
2 * Module Name: MainPage.xaml.cs
3 * Project: CSSL3FullScreen
4 * Copyright (c) Microsoft Corporation.
5 *
6 * This example illustrates how to use the full screen feature of Silverlight 3 and
7 * what the keyboard limitation is in full screen mode.
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * History:
14 * * 7/13/2009 02:00 PM Allen Chen Created
15 \***************************************************************************/
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Net;
21 using System.Windows;
22 using System.Windows.Controls;
23 using System.Windows.Documents;
24 using System.Windows.Input;
25 using System.Windows.Media;
26 using System.Windows.Media.Animation;
27 using System.Windows.Shapes;
29 namespace CSSL3FullScreen
31 public partial class MainPage : UserControl
33 public MainPage()
35 InitializeComponent();
37 // Attach the Loaded event to hook up events on load stage.
38 this.Loaded += new RoutedEventHandler(MainPage_Loaded);
42 void MainPage_Loaded(object sender, RoutedEventArgs e)
44 // Attach events of SilverlightHost to subscribe the
45 // FullScreenChanged and Resized event.
46 App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
47 App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
50 void Content_Resized(object sender, EventArgs e)
52 // When content get resized, refresh TextBlockShowSize control to
53 // show the size of the Silverlight plug-in.
54 RefreshTextBlockShowSize();
57 void Content_FullScreenChanged(object sender, EventArgs e)
59 // When full screen mode changed, refresh TextBlockShowSize
60 // control to show the size of the Silverlight plug-in.
61 RefreshTextBlockShowSize();
63 private void RefreshTextBlockShowSize()
65 // Show the size of the Silverlight plug-in on TextBlockShowSize
66 // control.
67 this.TextBlockShowSize.Text = string.Format("{0}*{1}",
68 App.Current.Host.Content.ActualWidth,
69 App.Current.Host.Content.ActualHeight);
71 private void UserControl_KeyDown(object sender, KeyEventArgs e)
73 // Show the input key on TextBlockShowKeyboardInput control.
74 this.TextBlockShowKeyboardInput.Text = e.Key.ToString();
77 private void Button_Click(object sender, RoutedEventArgs e)
79 // Switch to full screen mode or embeded mode.
80 App.Current.Host.Content.IsFullScreen =
81 !App.Current.Host.Content.IsFullScreen;